package com.song.tradition.page.details

import android.annotation.SuppressLint
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import com.song.tradition.entity.GrassData
import com.song.tradition.entity.grassData
import com.song.tradition.page.components.CustomTitleTopAppBar
import com.song.tradition.page.components.LinearGrassItemCard
import com.song.tradition.ui.theme.customBgColor
import com.song.tradition.ui.theme.customCardBgColor


@OptIn(ExperimentalMaterial3Api::class)
@SuppressLint("ResourceType")
@Composable
fun GrassDetailScreen(
    navController: NavController,
    data: GrassData
) {
    var grassDataCurrent= grassData.clone()
    grassDataCurrent = grassDataCurrent.filter { it.name != data.name }.toList().toTypedArray()
    Scaffold(
        topBar = {

            CustomTitleTopAppBar(title = data.name, navClick = {
                navController.popBackStack()
            })
        }
    ) {
        Surface(
            modifier = Modifier
                .fillMaxSize()
                .padding(paddingValues = it)
        ) {

            Column(
                modifier = Modifier
                    .fillMaxSize()
                    .background(customBgColor)
                    .verticalScroll(rememberScrollState())
                    .padding(horizontal = 16.dp, vertical = 8.dp)
            ) {

                Image(
                    painterResource(id = data.resId), contentDescription = "",
                    modifier = Modifier
                        .fillMaxWidth()
                        .clip(RoundedCornerShape(10.dp))
                        .background(customCardBgColor)
                        .shadow(elevation = 2.dp)
                )

                Spacer(modifier = Modifier.height(16.dp))

                Text(
                    text = data.description,
                    lineHeight = 30.sp,
                    modifier = Modifier.fillMaxWidth()
                )

                Spacer(modifier = Modifier.height(16.dp))

                Text(text = "性状:", fontSize = 22.sp, fontWeight = FontWeight.Bold)
                Spacer(modifier = Modifier.height(16.dp))
                Text(
                    text = data.character,
                    lineHeight = 30.sp,
                    modifier = Modifier.fillMaxWidth()
                )
                Spacer(modifier = Modifier.height(16.dp))

                Text(text = "其他草药", fontSize = 22.sp, fontWeight = FontWeight.Bold)
                Spacer(modifier = Modifier.height(16.dp))
                Column(modifier = Modifier.fillMaxWidth()) {
                    repeat(grassDataCurrent.size) { index ->
                        LinearGrassItemCard(data = grassDataCurrent[index])
                    }
                }

            }
        }
    }
}

